<?php
defined('SYSPATH') OR die('No direct access allowed.');
/**
 * login.php
 * @author ranuandra
 *
 * 10 Mei 2012 08:51:32
 *
 * 
 */
class Controller_Login extends Kohana_Nasmoco
{
	
	public function action_index()
	{
/*		print_r($_GET);
		$message = Request::current()->param('errlogin');
		echo $message;
		exit;*/
			if(isset($_POST['username']) and isset($_POST['password']))
			{
				//$user = Auth_ORM::instance();
				
				$status = Auth_ORM::instance()->login($_POST['username'], $_POST['password'], FALSE);
				
				if($status)
				{
					if(Auth_ORM::instance()->get_user()->activated == 0)
					{
						Auth_ORM::instance()->logout();
						Request::current()->redirect(URL::base());
						//echo "<script>window.location.replace(\"".URL::base()."login?errlogin=Username dan password tidak sesuai\")</script>";
						//echo "<script>window.location.replace("'".URL::base()."'")</script>";
						return;
					}
					else 
					{
						Request::current()->redirect(URL::base()."user");
					}
					//Request::current()->redirect(URL::base()."user");

				}
				else 
				{
					Request::current()->redirect(URL::base());
				}
			}	
	}
}